package com.api.devices.domain.query.intergration;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.api.common.config.ApiConfig;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@Getter
@Setter
public class ElementLatestScoreQuery {
    private String ipcCode;
    private String elementCode;
    private Long elementId;
    private JSONObject elementNameLocales;

    private Integer ipcSlot;
    private List<Integer> datColSet;
    private final String type = "element";
    private List data;

    public void setDatColSet(String datColSet) {
        if (StringUtils.isNotBlank(datColSet)) {
            this.datColSet = JSONArray.parseArray(datColSet).toList(Integer.class);
        }
    }

    public void setElementNameLocales(String elementNameLocales) {
        if (StringUtils.isNotBlank(elementNameLocales)) {
            this.elementNameLocales = JSONObject.parseObject(elementNameLocales);
        } else {
            this.elementNameLocales = null;
        }
    }

    public String getIntergrationName(String type, String endCode) {
        return ApiConfig.getTenant() + "_" + this.ipcCode
                + "_" + type + "_" + this.ipcSlot
                + "_" + this.elementCode + "_" + endCode + "_tracing_intergration";
    }
}
